//
//  YHYDetailViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/22.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYDetailViewController.h"
#import "YHYFindNameCell.h"
#import "YHYMyHighlightcell.h"
#import "YHYexperienceCell.h"
#import "YHYEducationcCell.h"
#import "YHYCaseShow.h"
//#import "YHYMoreCaseCell.h"
#import "YHYButtonTabBar.h"
#import "UIView+Five.h"
#import "WSFindButtonView.h"
#import "YHYAddViewController.h"
#import "LewPopupViewAnimationSpring.h"
#import "YHYWUViewController.h"

@interface YHYDetailViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,YHYTabBarGouTongAndShouCang>
{

    int row;

}
@property (nonatomic, strong) UICollectionView *collectionView;
//@property (nonatomic, strong) WSShareView *shareView;
@property (nonatomic, strong) WSCustomButton *shareBtn;
@property (nonatomic, strong) WSCustomButton *backBtn;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic,assign)BOOL isON;/**<点击沟通*/
@property (nonatomic, assign) BOOL isBa;
@property (nonatomic,retain)UIView *alertView;
@property (nonatomic,assign)BOOL isSelrct;
@property (nonatomic, strong) WSFindButtonView *buttonView;
@property (nonatomic, strong)  YHYButtonTabBar *bottonView;

@property (nonatomic, strong) UIView *view1;
@property (nonatomic, strong) UIView *view2;

@end

@implementation YHYDetailViewController

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
    self.title = @"设计师资料";
    //self.navigationController.tabBarController.tabBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _isSelect = YES;
    [self creatView];
    _isSelrct = NO;
    _isON = NO;
    
    _bottonView= [[YHYButtonTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50 * AUTO_WIDTH)];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]];
    NSLog(@"dddddd=%@",[user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]]);
    if ([user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]] == 0  ) {
      
         _bottonView.gouTongL.text = @"立即沟通"; // 判断时 需要掉接口 创建微简历 字段
    }
    else {
        _bottonView.xinImageView2.image = [UIImage imageNamed:@"tong"];
    
         _bottonView.gouTongL.text = @"继续沟通";
    }
    [_bottonView changeViewToTypeShopper];
    _bottonView.delegate = self;
    [self.view addSubview:_bottonView];
    [_bottonView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
    }];

    
    
    UIImageView *viewIV = [UIImageView new];
    viewIV.image = [UIImage imageNamed:@"purse_shadow"];
    //viewIV.backgroundColor = [UIColor redColor];
    [self.view addSubview:viewIV];
    
    [viewIV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 100 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
        //make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.height.mas_equalTo(60 * AUTO_HEIGHT);
        
    }];

    self.view.layer.contents=nil;
    
    //view1
    _view1=  [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height/2-100)];
    _view1.backgroundColor=HS;
    //***********************
    //这个属性可以设置寄宿图显示的区域
    _view1.layer.contentsRect=CGRectMake(0.0,0.0,1,0.5);
    
    
    [self.view addSubview:_view1];
    
    //view2
    _view2=[[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height/2,self.view.frame.size.width, self.view.frame.size.height/2-64)];
    
    _view2.backgroundColor=HS;
    
    _view2.layer.contentsRect=CGRectMake(0.0,5.0,1,0.5);
    
    
    [self.view addSubview:_view2];
    
    
    //********************
    //属性动画
    [UIView animateWithDuration:1.0 animations:^{
        
        _view1.frame=CGRectMake(0,-self.view.frame.size.height/2-100,self.view.frame.size.width,self.view.frame.size.height/2-100);
        
        _view2.frame=CGRectMake(0,self.view.frame.size.height+self.view.frame.size.height/2 ,self.view.frame.size.width,self.view.frame.size.height/2);
        
        
    } completion:^(BOOL finished) {
        [_view1 removeFromSuperview];
        [_view2 removeFromSuperview];
    }];
    
}




- (void)creatView{

//    self.shareBtn = [WSCustomButton buttonWithType:UIButtonTypeCustom];
//    self.shareBtn.frame = CGRectMake(0, 0, 30, 30);
//    [self.shareBtn setImage:[[UIImage imageNamed:@"navigation_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
//    [self.shareBtn addTarget:self action:@selector(btn1Action:) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:_shareBtn];
    
    
    
    self.backBtn = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    self.backBtn.frame = CGRectMake(0, 0, 30, 30);
    [self.backBtn setImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    [self.backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backBtn];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.sectionInset = UIEdgeInsetsMake(5 * AUTO_WIDTH, 0, 0 * AUTO_WIDTH, 0);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 80) collectionViewLayout:flowLayout];
   
    flowLayout.minimumLineSpacing =8 * AUTO_HEIGHT;
    self.collectionView.backgroundColor = LV;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [_collectionView registerClass:[YHYFindNameCell class] forCellWithReuseIdentifier:@"YHYFindNameCell"];
    
    [_collectionView registerClass:[YHYMyHighlightcell class] forCellWithReuseIdentifier:@"YHYMyHighlightcell"];
    
    [_collectionView registerClass:[YHYexperienceCell class] forCellWithReuseIdentifier:@"YHYexperienceCell"];
    
    [_collectionView registerClass:[YHYEducationcCell class] forCellWithReuseIdentifier:@"YHYEducationcCell"];
    
    [_collectionView registerClass:[YHYCaseShow class] forCellWithReuseIdentifier:@"YHYCaseShow"];
    
  //  [_collectionView registerClass:[YHYMoreCaseCell class] forCellWithReuseIdentifier:@"YHYMoreCaseCell"];
    [_collectionView reloadData];
    

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    
   // if (_isSelect == YES) {
        return 5;
  //  }
//    else if (_isSelect == NO){
//        return 6 + 3;
//      //  [_collectionView reloadData];
//    }
  //  return 0;

}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 3) {
        
        return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), 110.00 * AUTO_WIDTH );
    } else if (indexPath.row == 2) {
        
        return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), 140 * AUTO_HEIGHT);
    } else if (indexPath.row == 4) {
        
        return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), 410.00 * AUTO_WIDTH);
    } else if (indexPath.row == 0) {
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 125.00 * AUTO_WIDTH);
    } else if (indexPath.row == 1){
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 110.00 * AUTO_WIDTH);
    }
    
    //else if (indexPath.row == 5){
        
       // if (_isSelect == NO) {
       //    return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 0.00 * AUTO_WIDTH / 2);        }
//        else{
//       return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 80.00 * AUTO_WIDTH / 2);
//        }
//    }
    
    else {
        
         return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 410.00 * AUTO_WIDTH);
    }
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
  
    static NSString *name = @"YHYFindNameCell";
    YHYFindNameCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];
        
    
    return cell;
    }
    if (indexPath.row == 1) {
       static NSString *str = @"YHYMyHighlightcell";
        YHYMyHighlightcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        return cell;
         }
    if (indexPath.row == 2) {
  
    static NSString *str = @"YHYexperienceCell";
    YHYexperienceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        
    return cell;
    }
    
    if (indexPath.row == 3) {
   
    static NSString *str = @"YHYEducationcCell";
    YHYEducationcCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
    return cell;
        
    }
//    if (indexPath.row == 5) {
//        static NSString *str = @"YHYMoreCaseCell";
//        YHYMoreCaseCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
//        cell.mydelegate = self;
//        return cell;
//        
//    }
    else{
    
        
        static NSString *str = @"YHYCaseShow";
        YHYCaseShow *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        return cell;

    }
   // return nil;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row == 5) {
//        NSLog(@"fsd");
//    }
    
}

////协议
//- (void)presentNextShow{
//    _isSelect = NO;
//    YHYMoreCaseCell *cell = (YHYMoreCaseCell *)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:5 inSection:0]];
//   
//    [cell.button removeFromSuperview];
//    [_collectionView reloadData];
//}

- (void)backAction:(UIButton *)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)YHYgongTongTabBar{
    if (!self.isON) {
        
        
        if (self.isBa) {
            [self animateView];
            
            [self lew_presentPopupView:_alertView animation:[LewPopupViewAnimationSpring new] dismissed:^{
                
            }];
            
        }else{
            
            
            YHYWUViewController *yhy=[[YHYWUViewController alloc]init];
            [self.navigationController pushViewController:yhy animated:YES];
            _bottonView.xinImageView2.image = [UIImage imageNamed:@"tong"];
            
            _bottonView.gouTongL.text = @"继续沟通";
        }
        self.isBa =!self.isBa;

        
    }
    else{
        
        self.alertView.hidden = YES;
        //self.myScrollView.alpha = 1.0;
        
    }
    
    self.isON =! self.isON;  //  取 反 
    
    

}
- (void)findButtonClickWith:(FINDBUTTONCLICK)click{
//
    if (click == FINDBUTTONCLICKCOLLECT) {
        
        click = FINDBUTTONCLICKCOLLECT;
        self.isSelrct = !self.isSelrct;
        if (self.isSelrct) {
          //self.xinImageView.image = [UIImage imageNamed:@"heart"];
            [self.view Message:@"收藏成功" HiddenAfterDelay:1];
        }
        else{
            NSLog(@"dd");
           
         //self.xinImageView.image = [UIImage imageNamed:@"heartShi"];
            [self.view Message:@"取消收藏" HiddenAfterDelay:1];
            
        }
        
        
    }
    
    
    
    if (click == FINDBUTTONCLICKTALK) {
        [self YHYgongTongTabBar];
        
        NSString *passWord= [NSString stringWithFormat:@"%ld",(long)self.indexPath.row];
        NSUserDefaults *user=[NSUserDefaults standardUserDefaults];

        [user setObject:passWord forKey:passWord];
        
    }
    
    if (click == FINDBUTTONCLICKCENTER) {
        [self buttonView];
        [UIView animateWithDuration:0.3 animations:^{
            
            _buttonView.frame = CGRectMake(0, SCREEN_HEIGHT - 160 * AUTO_WIDTH - 64, SCREEN_WIDTH, 160 * AUTO_WIDTH);
        }];

    }
    
//
//    
}
- (WSFindButtonView *)buttonView {
    
    if (!_buttonView) {
        _buttonView = [[WSFindButtonView alloc] init];
        [self.view addSubview:_buttonView];
    }
    
    return _buttonView;
}


- (void)animateView{
    
    self.alertView = [[UIView alloc]init];
    self.alertView.backgroundColor = [UIColor colorWithWhite:0.985 alpha:1.000];
    [self.view addSubview:self.alertView];

    
//    NSInteger numberOfOptions = 1;
//    NSArray *items = @[
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"arrow"] title:@"Next"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"attachment"] title:@"Attach"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"block"] title:@"Cancel"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"bluetooth"] title:@"Bluetooth"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"cube"] title:@"Deliver"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"download"] title:@"Download"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"enter"] title:@"Enter"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"file"] title:@"Source Code"],
//                       [[RNGridMenuItem alloc] initWithImage:[UIImage imageNamed:@"github"] title:@"Github"]
//                       ];

    
    
//    RNGridMenu *av = [[RNGridMenu alloc] initWithItems:[items subarrayWithRange:NSMakeRange(0, numberOfOptions)]];
//    av.delegate = self;
//    
//    [av showInViewController:self center:CGPointMake(self.view.bounds.size.width/2.f, self.view.bounds.size.height/2.f)];
    
    [UIView animateWithDuration:0.08 animations:^{
        
        //        self.aView.frame = CGRectMake(40, 90, 120, 60);
        self.alertView.center = CGPointMake(self.view.frame.size.width/2 , 0 );
        self.alertView.frame = CGRectMake(30.00*AUTO_WIDTH,0, self.view.frame.size.width - 60.00*AUTO_WIDTH, 250.00*AUTO_WIDTH);
        //
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.005 animations:^{
            self.alertView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 );
            
            
            self.alertView.alpha = 1;
            
        }];
        
        
    }];
    
    
    self.alertView.layer.masksToBounds = YES;
    self.alertView.layer.cornerRadius = 15.00*AUTO_WIDTH;
    self.alertView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
    
    
    UIButton *quxiaoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [quxiaoButton setImage:[UIImage imageNamed:@"picker_can"] forState:UIControlStateNormal];
    [quxiaoButton addTarget:self action:@selector(quxiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    quxiaoButton.backgroundColor = [UIColor whiteColor];
    [self.alertView addSubview:quxiaoButton];
    [quxiaoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.alertView).offset(7.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-10.00*AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(20.00*AUTO_WIDTH, 20.00*AUTO_WIDTH));
        
    }];
    
    UIImageView *tishiImageview = [[UIImageView alloc]init];
    tishiImageview.image = [UIImage imageNamed:@"gantan"];
    //tishiImageview.backgroundColor = [UIColor whiteColor];
    [self.alertView addSubview:tishiImageview];
    [tishiImageview  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.alertView).offset(25.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset((self.view.frame.size.width - 115.00*AUTO_WIDTH)/2);
        make.size.mas_equalTo(CGSizeMake(95.00/2*AUTO_WIDTH, 95.00/2*AUTO_WIDTH));
        
    }];
    
    UILabel *aLabel = [[UILabel alloc]init];
    aLabel.backgroundColor =[UIColor colorWithWhite:0.985 alpha:1.000];
    [self.alertView addSubview:aLabel];
    aLabel.text = @"立即添加任务";
    aLabel.textColor = HS;
    aLabel.textAlignment = NSTextAlignmentCenter;
    aLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [aLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(tishiImageview.mas_bottom).offset(20.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(100.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-100.00*AUTO_WIDTH);
        // make.size.mas_equalTo(CGSizeMake(22, 30.00*HEIGHT));
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    
    
    UILabel *bLabel = [[UILabel alloc]init];
    bLabel.backgroundColor =[UIColor colorWithWhite:0.985 alpha:1.000];
    [self.alertView addSubview:bLabel];
    bLabel.text = @"与设计师在线交流";
    aLabel.textColor = HS;
    bLabel.textAlignment = NSTextAlignmentCenter;
    bLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [bLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(aLabel.mas_bottom).offset(20.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(60.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-60.00*AUTO_WIDTH);
        // make.size.mas_equalTo(CGSizeMake(22, 30.00*HEIGHT));
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    
    UIButton *chungajianButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [chungajianButton addTarget:self action:@selector(chuangjianActon:) forControlEvents:UIControlEventTouchUpInside];
    chungajianButton.layer.masksToBounds = YES;
    chungajianButton.layer.cornerRadius = LITTLETEXTFONT*TEXTWEIGHT;
    [chungajianButton setTitle:@"添加任务" forState:UIControlStateNormal];
    chungajianButton.backgroundColor=GH;
    chungajianButton.titleLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [chungajianButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.alertView addSubview:chungajianButton];
    [chungajianButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.alertView.mas_bottom).offset(-20.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-80.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(80.00*AUTO_WIDTH);
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    
    
}

-(void) chuangjianActon:(UIButton *) btn
{
    YHYAddViewController *addview=[[YHYAddViewController alloc]init];
    [self.navigationController pushViewController:addview animated:YES];
}

-(void) quxiaoAction:(UIButton*) btn
{
    self.isON =NO;
    self.alertView.alpha=0;
}

@end
